<?php
/**
 * 区外成绩对比
 * 
 * @version 1.0
 * @author jinyue.wang
 * @date 2013-12-15
 */
class DefaultController extends FController {

    public $user_school_list;
    public $user_subject_list;
    public $user_role_list;
    public $exam_id;

    public function accessRules() {
        $config = array(
            'index' => 1
        );
        return ZRole::auth("comparison", $config);
    }

    public function __common() {
        parent::init();
        if (empty($this->cLoginUser)) {
            $this->redirect($this->createUrl('/site/login'));
        } else {
            $userLoginUser = $this->cLoginUser;

            $this->user_role_list = isset($userLoginUser['cuser']['role_id']) ? $userLoginUser['cuser']['role_id'] : '';
            $this->user_school_list = isset($userLoginUser['cuser']['school']['school_id']) ? $userLoginUser['cuser']['school']['school_id'] : '';
            $this->user_subject_list = isset($userLoginUser['cuser']['school']['subject_id']) ? $userLoginUser['cuser']['school']['subject_id'] : '';

            $zRow = new ZRole();
            //得到学校对应的考试
            $exam_list = $zRow->_getSchoolExam($this->user_school_list);
            if (!empty($exam_list)) {
                $this->exam_id = implode(',', $exam_list);
            }
        }

        $this->commonScript();
        Yii::app()->clientScript->registerCssFile(THEME_CSS_URL . '/module_Sip.css');
    }

    public function actionIndex() {

        $this->__common();

        $zExam = new zExam();
        $examArray = $zExam->_getExamObject($this->exam_id, $this->user_role_list);

        $this->title = '区外学校对比分析';
        $this->render('index', array(
            'examArray' => $examArray
        ));
    }

    public function actionList() {
        $this->__common();
        Yii::app()->clientScript->registerCssFile(THEME_CSS_URL . '/chart.css');
        Yii::app()->clientScript->registerScriptFile(STATICS_URL . "/js/Highcharts/js/highcharts.js");
        Yii::app()->clientScript->registerScriptFile(STATICS_URL . "/js/Highcharts/js/modules/exporting.js");
        Yii::app()->clientScript->registerScriptFile(THEME_JS_URL . "/chart.js");
        $this->layout = "//layouts/main_other";

        //项目对应的分数线
        $exam_id = $this->request->getParam('exam_id');
        $info = $this->request->getParam('info');
        $zExam = new zExam();
        $scorse = $zExam->_getEduScoreArray($exam_id);   //得到考试分数线
        $ylk_point = $elk_point = $ywk_point = $ewk_point = $glk_point = $gwk_point = 0;
        if (isset($scorse[1])) {
            $ylk_point = $scorse[1]['score_type1'];
            $elk_point = $scorse[1]['score_type2'];
            $glk_point = $scorse[1]['score_type3'];
        }
        if (isset($scorse[2])) {
            $ywk_point = $scorse[2]['score_type1'];
            $ewk_point = $scorse[2]['score_type2'];
            $gwk_point = $scorse[2]['score_type3'];
        }
        
        $schooldata = array();
        
        $lwSubject = self::_getDBnum(); //得到分数段科目对应的栏位
        
        $out_scorse = $return_data = $ddata = $sdata = $gdata = array();
        //得到达C率
        $zExamRule = new ZExamRule();
        $garding_cid = $zExamRule->_getGradingCpoint();
        $garding_bid = $zExamRule->_getGradingBpoint();

        $gcdata = $gbdata = array();
        if ($garding_cid > 0) {
            //得到达标科目分数
            $gradingsql = 'SELECT * FROM "{{point_grading}}" WHERE "exam_id" = :exam_id AND "grading_id" = :g_id ';
            $gresult = Yii::app()->db->createCommand($gradingsql);
            $gresult->bindParam(':exam_id', $exam_id, PDO::PARAM_STR);
            $gresult->bindParam(':g_id', $garding_cid, PDO::PARAM_STR);
            $gradingdatac = $gresult->queryAll();
            if (!empty($gradingdatac)) {
                foreach ($gradingdatac as $gcVal) {
                    $gcdata[$gcVal['subject_id']] = $gcVal['score'];
                }
            }
        }
        //得到达B率
        if ($garding_bid > 0) {
            //得到达标科目分数
            $gradingsql = 'SELECT * FROM "{{point_grading}}" WHERE "exam_id" = :exam_id AND "grading_id" = :g_id ';
            $gresult = Yii::app()->db->createCommand($gradingsql);
            $gresult->bindParam(':exam_id', $exam_id, PDO::PARAM_STR);
            $gresult->bindParam(':g_id', $garding_bid, PDO::PARAM_STR);
            $gradingdatab = $gresult->queryAll();
            if (!empty($gradingdatab)) {
                foreach ($gradingdatab as $gbVal) {
                    $gbdata[$gbVal['subject_id']] = $gbVal['score'];
                }
            }
        }
        
        $zEdu = new ZEdu();
        //得到科目
        $subjectObject = $zEdu->_getSubjectObject();
        $gardingCArray = $zExamRule->_getExamGarding($exam_id, $garding_cid, $subjectObject); //得到想关类型分数C
        $gardingBArray = $zExamRule->_getExamGarding($exam_id, $garding_bid, $subjectObject); //得到想关类型分数B
        $schoolArray = array();
        $qWhere = '';
    	if ($this->user_role_list != 1) {
            $zExam = new zExam();
            $qWhere = $zExam->_getSchoolInfoList($this->user_school_list);
        }
        //此学校所有数据(区外)
        $schoolsql = 'SELECT * FROM "{{student_out_score}}" WHERE "exam_id" = :exam_id AND "statis" = \'T\'';  //是否加用户所属学校条件
        if(!empty($qWhere)){
        	$schoolsql .= " AND ( ".$qWhere." ) ";
        }
        $schoolary = Yii::app()->db->createCommand($schoolsql);
        $schoolary->bindParam(':exam_id',$exam_id,PDO::PARAM_STR);
        $schoolData = $schoolary->queryAll();

        if(!empty($schoolData)){
            foreach ($schoolData as $value) {     
            	$skf = 0; //各个分数人数
                $out_scorse[$value['school_code']]['school_name'] = $value['school_name'];
                $out_scorse[$value['school_code']]['school_code'] = $value['school_code'];
                $schoolArray[$value['school_code']] = $value['school_name'];
                //达B的类别科目信息
                $dArray = $sArray = $pArray = array();
                if(!empty($value['disciplin_code'])){
                    if(isset($ddata[$value['disciplin_code']])){
                        $dArray = $ddata[$value['disciplin_code']];
                    }else{
                        $disciplinsql = 'SELECT "disciplin_id" FROM "{{disciplin}}" WHERE "disciplin_code" = :d_code ';
                        $dresult = Yii::app()->db->createCommand($disciplinsql);
                        $dresult->bindParam(':d_code',$value['disciplin_code'],PDO::PARAM_STR);
                        $dArray = $dresult->queryRow();
                        $ddata[$value['disciplin_code']] = $dArray;
                    }
                    //得到科别信息
                    if(!empty($dArray)){
                        if (isset($sdata[$dArray['disciplin_id']])) {
                            $sArray = $sdata[$dArray['disciplin_id']];
                        } else {
                            $disciplin_subjectsql = 'SELECT "subject_id" FROM "{{disciplin_subject}}" WHERE "disciplin_id" = :d_id ';
                            $subjectids = Yii::app()->db->createCommand($disciplin_subjectsql);
                            $subjectids->bindParam(':d_id', $dArray['disciplin_id'], PDO::PARAM_STR);
                            $sArray = $subjectids->queryAll();
                            $sdata[$dArray['disciplin_id']] = $sArray;
                        }
                    }
                } 
                $skf = $value['ywf'] + $value['sxf'] + $value['yyf'];
                
                //得到文理科人数
                if(!isset($out_scorse[$value['school_code']]['l_people'])){
                    $out_scorse[$value['school_code']]['l_people'] = 0;
                }
                if(!isset($out_scorse[$value['school_code']]['w_people'])){
                    $out_scorse[$value['school_code']]['w_people'] = 0;
                }
                
                //得到分数线人数
                if($value['disciplin_type'] == 1){
                    if(!isset($out_scorse[$value['school_code']]['yl_num'])){
                        $out_scorse[$value['school_code']]['yl_num'] = 0;  //一本人数
                    }
                    if(!isset($out_scorse[$value['school_code']]['el_num'])){
                        $out_scorse[$value['school_code']]['el_num'] = 0; //二本人数
                    }
                    if (!isset($out_scorse[$value['school_code']]['ybbl_num'])) {
                        $out_scorse[$value['school_code']]['ybbl_num'] = 0; //2b
                    }
                    if (!isset($out_scorse[$value['school_code']]['ebcl_num'])) {
                        $out_scorse[$value['school_code']]['ebcl_num'] = 0; //达到bc
                    }
                    if (!isset($out_scorse[$value['school_code']]['eccl_num'])) {
                        $out_scorse[$value['school_code']]['eccl_num'] = 0; //达到2c
                    }
                    if(!isset($out_scorse[$value['school_code']]['gl_num'])){
                        $out_scorse[$value['school_code']]['gl_num'] = 0; //高分段人数
                    }
                    if(!isset($out_scorse[$value['school_code']]['lsk'])){
                        $out_scorse[$value['school_code']]['lsk']  = 0;
                    }
                    
                    $lndb = 0;
                    //理科分数线人数
                    if($skf >= $ylk_point){
                        $out_scorse[$value['school_code']]['yl_num'] += 1;
                        if(!empty($sArray)){
                            foreach($sArray as $sVal){
                                $pkey = isset($lwSubject[$sVal['subject_id']]) ? $lwSubject[$sVal['subject_id']] : ''; //科目栏位
                                $pcpoint = isset($gcdata[$sVal['subject_id']]) ? $gcdata[$sVal['subject_id']] : 0;  //C分数线
                                $pbpoint = isset($gbdata[$sVal['subject_id']]) ? $gbdata[$sVal['subject_id']] : 0;  //B分数线
                                //得到达2b的人数
                                $nPoint = isset($value[$pkey]) ? $value[$pkey] : 0; //科目分数
                                if ($nPoint >= $pbpoint) {
                                    $lndb += 2;  //达到b
                                }
                            }
                            if ($lndb >= 4) {
                                $out_scorse[$value['school_code']]['ybbl_num'] += 1;  //理科达到2b人数
                            }
                        }
                    }
                    $lndb = 0;
					if($skf >= $elk_point){
                        $out_scorse[$value['school_code']]['el_num'] += 1;
                        if(!empty($sArray)){
                            foreach($sArray as $sVal){
                                $pkey = isset($lwSubject[$sVal['subject_id']]) ? $lwSubject[$sVal['subject_id']] : ''; //科目栏位
                                $pcpoint = isset($gcdata[$sVal['subject_id']]) ? $gcdata[$sVal['subject_id']] : 0;  //C分数线
                                $pbpoint = isset($gbdata[$sVal['subject_id']]) ? $gbdata[$sVal['subject_id']] : 0;  //B分数线
                                //得到达bc的人数
                                $nPoint = isset($value[$pkey]) ? $value[$pkey] : 0; //科目分数
                                if ($nPoint >= $pbpoint) {
                                    $lndb += 3;  //达到b
                                } elseif ($nPoint >= $pcpoint) {
                                    $lndb += 2;  //达到c
                                }
                            }
                            if ($lndb >=5) {
                                $out_scorse[$value['school_code']]['ebcl_num'] += 1;  //理科达到bc人数
                                $out_scorse[$value['school_code']]['eccl_num'] += 1; // 理科达到2c人数
                            }elseif($lndb>=4){
                                $out_scorse[$value['school_code']]['eccl_num'] += 1; //理科达到2c人数
                            }
                        }
                    }     
                    //理科高分段
                    if ($skf >= $glk_point){
                        $out_scorse[$value['school_code']]['gl_num'] += 1;
                    }
                    //理科最高分
                    if($skf>=$out_scorse[$value['school_code']]['lsk']){
                        $out_scorse[$value['school_code']]['lsk'] = $skf;
                    }
                    
                    $out_scorse[$value['school_code']]['l_people'] += 1;
                }elseif($value['disciplin_type'] == 2){ 
                    if(!isset($out_scorse[$value['school_code']]['yw_num'])){
                        $out_scorse[$value['school_code']]['yw_num'] = 0;  //一本人数
                    }
                    if(!isset($out_scorse[$value['school_code']]['ew_num'])){
                        $out_scorse[$value['school_code']]['ew_num'] = 0; //二本人数
                    }
                    if (!isset($out_scorse[$value['school_code']]['ybbw_num'])) {
                        $out_scorse[$value['school_code']]['ybbw_num'] = 0; //达2B
                    }
                    if (!isset($out_scorse[$value['school_code']]['ebcw_num'])) {
                        $out_scorse[$value['school_code']]['ebcw_num'] = 0; //达bc
                    }
                    if (!isset($out_scorse[$value['school_code']]['eccw_num'])) {
                        $out_scorse[$value['school_code']]['eccw_num'] = 0; //达2c
                    }
                    if(!isset($out_scorse[$value['school_code']]['gw_num'])){
                        $out_scorse[$value['school_code']]['gw_num'] = 0; //高分段
                    }
                    if(!isset($out_scorse[$value['school_code']]['wsk'])){
                        $out_scorse[$value['school_code']]['wsk']  = 0; 
                    }
                    
                    $lndb = 0;
                    //文科分数线人数
                    if($skf >= $ywk_point){
                        $out_scorse[$value['school_code']]['yw_num'] += 1;
                        if(!empty($sArray)){
                            foreach($sArray as $sVal){
                                $pkey = isset($lwSubject[$sVal['subject_id']]) ? $lwSubject[$sVal['subject_id']] : ''; //科目栏位
                                $pcpoint = isset($gcdata[$sVal['subject_id']]) ? $gcdata[$sVal['subject_id']] : 0;  //C分数线
                                $pbpoint = isset($gbdata[$sVal['subject_id']]) ? $gbdata[$sVal['subject_id']] : 0;  //B分数线
                                //得到达2b的人数
                                $nPoint = isset($value[$pkey]) ? $value[$pkey] : 0; //科目分数
                                if ($nPoint >= $pbpoint) {
                                    $lndb += 2;  //达到b
                                }
                            }
                            if ($lndb >= 4) {
                                $out_scorse[$value['school_code']]['ybbw_num'] += 1;  //理科达到2b人数
                            }
                        }
                    }
                    $lndb = 0;
                    //二本线
					if($skf >= $ewk_point){
                        $out_scorse[$value['school_code']]['ew_num'] += 1;
                        if(!empty($sArray)){
                            foreach($sArray as $sVal){
                                $pkey = isset($lwSubject[$sVal['subject_id']]) ? $lwSubject[$sVal['subject_id']] : ''; //科目栏位
                                $pcpoint = isset($gcdata[$sVal['subject_id']]) ? $gcdata[$sVal['subject_id']] : 0;  //C分数线
                                $pbpoint = isset($gbdata[$sVal['subject_id']]) ? $gbdata[$sVal['subject_id']] : 0;  //B分数线
                                //得到达bc的人数
                                $nPoint = isset($value[$pkey]) ? $value[$pkey] : 0; //科目分数
                                if ($nPoint >= $pbpoint) {
                                    $lndb += 3;  //达到b
                                } elseif ($nPoint >= $pcpoint) {
                                    $lndb += 2;  //达到c
                                }
                            }
                            if ($lndb >= 5) {
                                $out_scorse[$value['school_code']]['ebcw_num'] += 1;  //理科达到bc人数
                                $out_scorse[$value['school_code']]['eccw_num'] += 1; // 理科达到2c人数
                            }elseif($lndb>=4){
                                $out_scorse[$value['school_code']]['eccw_num'] += 1; //理科达到2c人数
                            }
                        }
                    }
                    //文科高分段人数
                    if ($skf >= $gwk_point){
                        $out_scorse[$value['school_code']]['gw_num'] += 1;
                    }
                    //文科最高分
                    if($skf>=$out_scorse[$value['school_code']]['wsk']){
                        $out_scorse[$value['school_code']]['wsk'] = $skf;
                    }
                    $out_scorse[$value['school_code']]['w_people'] += 1;
                }   
            }
            
            //重构数据
            if (!empty($out_scorse)) {
                foreach ($out_scorse as $skey => $value) {
                    $schooldata[$value['school_code']] = $value['school_name']; 
                    if ($value['l_people'] > 0) {
                        $value['ylk_num'] = sprintf('%.2f%%', $value['yl_num'] / $value['l_people'] * 100);
                        $value['elk_num'] = sprintf('%.2f%%', $value['el_num'] / $value['l_people'] * 100);
                        $value['glk_num'] = $value['gl_num'];
                        $value['lskf'] = $value['lsk'];
                        
                        $value['yldb_num'] = sprintf('%.2f%%', $value['ybbl_num'] / $value['l_people'] * 100);
                        $value['elcc_num'] = sprintf('%.2f%%', $value['eccl_num'] / $value['l_people'] * 100);
                        $value['eldb_num'] = sprintf('%.2f%%', $value['ebcl_num'] / $value['l_people'] * 100);
                    }else{
                        $value['ylk_num'] = 0;
                        $value['elk_num'] = 0;
                        $value['glk_num'] = 0;
                        $value['lskf'] = 0;
                        $value['yldb_num'] = 0;
                        $value['eldb_num'] = 0;
                        $value['elcc_num'] = 0;
                    }
                    if ($value['w_people'] > 0) {
                        $value['ywk_num'] = sprintf('%.2f%%', $value['yw_num'] / $value['w_people'] * 100);
                        $value['ewk_num'] = sprintf('%.2f%%', $value['ew_num'] / $value['w_people'] * 100);
                        $value['gwk_num'] = $value['gw_num'];
                        $value['wskf'] = $value['wsk'];
                        
                        $value['ywdb_num'] = sprintf('%.2f%%', $value['ybbw_num'] / $value['w_people'] * 100);
                        $value['ewcc_num'] = sprintf('%.2f%%', $value['eccw_num'] / $value['w_people'] * 100);
                        $value['ewdb_num'] = sprintf('%.2f%%', $value['ebcw_num'] / $value['w_people'] * 100);
                    } else {
                        $value['ywk_num'] = 0;
                        $value['ewk_num'] = 0;
                        $value['gwk_num'] = 0;
                        $value['wskf'] = 0;
                        $value['ywdb_num'] = 0;
                        $value['ewcc_num'] = 0;
                        $value['ewdb_num'] = 0;
                    }
                    $out_scorse[$skey] = $value;
                }
            }
        }
        
        //此学校所有数据(区内)
        $nout_scorse = array();
        $ssql = 'SELECT * FROM "{{student}}" WHERE "exam_id" = :exam_id AND "statis" = \'T\'';  //是否加用户所属学校条件
        $sary = Yii::app()->db->createCommand($ssql);
        $sary->bindParam(':exam_id',$exam_id,PDO::PARAM_STR);
        $sData = $sary->queryAll();
        if(!empty($sData)){
            foreach($sData as $sValue){
                $sValue['school_code'] = 'y00q';
                $nout_scorse['y00q']['school_name'] = '园区';
                $nout_scorse['y00q']['school_code'] = 'y0q';
                //达B的类别科目信息
                $dArray = $sArray = $pArray = array();
                if(!empty($sValue['disciplin_code'])){
                    if(isset($ddata[$sValue['disciplin_code']])){
                        $dArray = $ddata[$sValue['disciplin_code']];
                    }else{
                        $disciplinsql = 'SELECT "disciplin_id" FROM "{{disciplin}}" WHERE "disciplin_code" = :d_code ';
                        $dresult = Yii::app()->db->createCommand($disciplinsql);
                        $dresult->bindParam(':d_code',$sValue['disciplin_code'],PDO::PARAM_STR);
                        $dArray = $dresult->queryRow();
                        $ddata[$sValue['disciplin_code']] = $dArray;
                    }
                    //得到科别信息
                    if(!empty($dArray)){
                        if (isset($sdata[$dArray['disciplin_id']])) {
                            $sArray = $sdata[$dArray['disciplin_id']];
                        } else {
                            $disciplin_subjectsql = 'SELECT "subject_id" FROM "{{disciplin_subject}}" WHERE "disciplin_id" = :d_id ';
                            $subjectids = Yii::app()->db->createCommand($disciplin_subjectsql);
                            $subjectids->bindParam(':d_id', $dArray['disciplin_id'], PDO::PARAM_STR);
                            $sArray = $subjectids->queryAll();
                            $sdata[$dArray['disciplin_id']] = $sArray;
                        }
                    }
                } 
                $skf = $sValue['ywf'] + $sValue['sxf'] + $sValue['yyf'];
                
                //得到文理科人数
                if(!isset($nout_scorse[$sValue['school_code']]['l_people'])){
                    $nout_scorse[$sValue['school_code']]['l_people'] = 0;  //一本人数
                }
                if(!isset($nout_scorse[$sValue['school_code']]['w_people'])){
                    $nout_scorse[$sValue['school_code']]['w_people'] = 0;  //一本人数
                }
                //得到分数线人数
                if($sValue['disciplin_type'] == 1){
                    if(!isset($nout_scorse[$sValue['school_code']]['yl_num'])){
                        $nout_scorse[$sValue['school_code']]['yl_num'] = 0;  //一本人数
                    }
                    if(!isset($nout_scorse[$sValue['school_code']]['el_num'])){
                        $nout_scorse[$sValue['school_code']]['el_num'] = 0; //二本人数
                    }
                    if (!isset($nout_scorse[$sValue['school_code']]['nlbb_num'])) {
                        $nout_scorse[$sValue['school_code']]['nlbb_num'] = 0; //达到2B
                    }
                    if (!isset($nout_scorse[$sValue['school_code']]['nlbc_num'])) {
                        $nout_scorse[$sValue['school_code']]['nlbc_num'] = 0; //达到2C
                    }
                    if (!isset($nout_scorse[$sValue['school_code']]['nlcc_num'])) {
                        $nout_scorse[$sValue['school_code']]['nlcc_num'] = 0; //达到2C
                    }
                    if(!isset($nout_scorse[$sValue['school_code']]['gl_num'])){
                        $nout_scorse[$sValue['school_code']]['gl_num'] = 0; //高分段人数
                    }
                    if(!isset($nout_scorse[$sValue['school_code']]['lsk'])){
                        $nout_scorse[$sValue['school_code']]['lsk']  = 0;
                    }
                    
                    $lndb = 0;
                    //理科分数线人数
                    if($skf >= $ylk_point){
                        $nout_scorse[$sValue['school_code']]['yl_num'] += 1;
                        if(!empty($sArray)){
                            foreach($sArray as $sVal){
                                $pkey = isset($lwSubject[$sVal['subject_id']]) ? $lwSubject[$sVal['subject_id']] : ''; //科目栏位
                                $pcpoint = isset($gcdata[$sVal['subject_id']]) ? $gcdata[$sVal['subject_id']] : 0;  //C分数线
                                $pbpoint = isset($gbdata[$sVal['subject_id']]) ? $gbdata[$sVal['subject_id']] : 0;  //B分数线
                                //得到达2b的人数
                                $nPoint = isset($sValue[$pkey]) ? $sValue[$pkey] : 0; //科目分数
                                if ($nPoint >= $pbpoint) {
                                    $lndb += 2;  //达到b
                                }
                            }
                            if ($lndb >= 4) {
                                $nout_scorse[$sValue['school_code']]['nlbb_num'] += 1;  //理科达到2b人数
                            }
                        }
                    }
                    $lndb = 0;
					if($skf >= $elk_point){
                        $nout_scorse[$sValue['school_code']]['el_num'] += 1;
                        if(!empty($sArray)){
                            foreach($sArray as $sVal){
                                $pkey = isset($lwSubject[$sVal['subject_id']]) ? $lwSubject[$sVal['subject_id']] : ''; //科目栏位
                                $pcpoint = isset($gcdata[$sVal['subject_id']]) ? $gcdata[$sVal['subject_id']] : 0;  //C分数线
                                $pbpoint = isset($gbdata[$sVal['subject_id']]) ? $gbdata[$sVal['subject_id']] : 0;  //B分数线
                                //得到达bc的人数
                                $nPoint = isset($sValue[$pkey]) ? $sValue[$pkey] : 0; //科目分数
                                if ($nPoint >= $pbpoint) {
                                    $lndb += 3;  //达到b
                                } elseif ($nPoint >= $pcpoint) {
                                    $lndb += 2;  //达到c
                                    }
                                }
                            if ($lndb >= 5) {
                                $nout_scorse[$sValue['school_code']]['nlbc_num'] += 1;  //理科达到bc人数
                                $nout_scorse[$sValue['school_code']]['nlcc_num'] += 1; // 理科达到2c人数
                            }elseif($lndb>=4){
                                $nout_scorse[$sValue['school_code']]['nlcc_num'] += 1; //理科达到2c人数
                            }
                            }
                        }
                    //理科高分段
                    if ($skf >= $glk_point) {
                        $nout_scorse[$sValue['school_code']]['gl_num'] += 1;
                    }     
                    
                    //理科最高分
                    if($skf>$nout_scorse[$sValue['school_code']]['lsk']){
                        $nout_scorse[$sValue['school_code']]['lsk'] = $skf;
                    }
                    
                    $nout_scorse[$sValue['school_code']]['l_people'] += 1;
                }elseif($sValue['disciplin_type'] == 2){ 
                    if(!isset($nout_scorse[$sValue['school_code']]['yw_num'])){
                        $nout_scorse[$sValue['school_code']]['yw_num'] = 0;  //一本人数
                    }
                    if(!isset($nout_scorse[$sValue['school_code']]['ew_num'])){
                        $nout_scorse[$sValue['school_code']]['ew_num'] = 0; //二本人数
                    }
                    if (!isset($nout_scorse[$sValue['school_code']]['nwbb_num'])) {
                        $nout_scorse[$sValue['school_code']]['nwbb_num'] = 0; //达B
                    }
                    if (!isset($nout_scorse[$sValue['school_code']]['nwbc_num'])) {
                        $nout_scorse[$sValue['school_code']]['nwbc_num'] = 0; //达bc
                    }
                    if (!isset($nout_scorse[$sValue['school_code']]['nwcc_num'])) {
                        $nout_scorse[$sValue['school_code']]['nwcc_num'] = 0; //达cc
                    }
                    if(!isset($nout_scorse[$sValue['school_code']]['gw_num'])){
                        $nout_scorse[$sValue['school_code']]['gw_num'] = 0; //高分段
                    }
                    if(!isset($nout_scorse[$sValue['school_code']]['wsk'])){
                        $nout_scorse[$sValue['school_code']]['wsk']  = 0; 
                    }
                    
                
                        
                        
            
        
        
    
        
		
		

		
		
		
		
        
					
                    
                    $lndb = 0;
                    //理科分数线人数
                    if ($skf >= $ywk_point) {
                        $nout_scorse[$sValue['school_code']]['yw_num'] += 1;
                        if (!empty($sArray)) {
                            foreach ($sArray as $sVal) {
                                $pkey = isset($lwSubject[$sVal['subject_id']]) ? $lwSubject[$sVal['subject_id']] : ''; //科目栏位
                                $pcpoint = isset($gcdata[$sVal['subject_id']]) ? $gcdata[$sVal['subject_id']] : 0;  //C分数线
                                $pbpoint = isset($gbdata[$sVal['subject_id']]) ? $gbdata[$sVal['subject_id']] : 0;  //B分数线
                                //得到达2b的人数
                                $nPoint = isset($sValue[$pkey]) ? $sValue[$pkey] : 0; //科目分数
                                if ($nPoint >= $pbpoint) {
                                    $lndb += 2;  //达到b
										}
									}
                            if ($lndb >= 4) {
                                $nout_scorse[$sValue['school_code']]['nwbb_num'] += 1;  //理科达到2b人数
							}
						}
                    } 
                    $lndb = 0;
					if ($skf >= $ewk_point) {
                        $nout_scorse[$sValue['school_code']]['ew_num'] += 1;
                        if (!empty($sArray)) {
                            foreach ($sArray as $sVal) {
                                $pkey = isset($lwSubject[$sVal['subject_id']]) ? $lwSubject[$sVal['subject_id']] : ''; //科目栏位
                                $pcpoint = isset($gcdata[$sVal['subject_id']]) ? $gcdata[$sVal['subject_id']] : 0;  //C分数线
                                $pbpoint = isset($gbdata[$sVal['subject_id']]) ? $gbdata[$sVal['subject_id']] : 0;  //B分数线
                                //得到达bc的人数
                                $nPoint = isset($sValue[$pkey]) ? $sValue[$pkey] : 0; //科目分数
                                if ($nPoint >= $pbpoint) {
                                    $lndb += 3;  //达到b
                                } elseif ($nPoint >= $pcpoint) {
                                    $lndb += 2;  //达到c
                                }
							}
                            if ($lndb >= 5) {
                                $nout_scorse[$sValue['school_code']]['nwbc_num'] += 1;  //理科达到bc人数
                                $nout_scorse[$sValue['school_code']]['nwcc_num'] += 1; // 理科达到2c人数
                            }elseif($lndb>=4){
                                $nout_scorse[$sValue['school_code']]['nwcc_num'] += 1; //理科达到2c人数
							}
                        }
							}
                    //文科高分段人数
                    if ($skf >= $gwk_point) {
                        $nout_scorse[$sValue['school_code']]['gw_num'] += 1;
							}
                    //文科最高分
                    if ($skf > $nout_scorse[$sValue['school_code']]['wsk']) {
                        $nout_scorse[$sValue['school_code']]['wsk'] = $skf;
							}
                    $nout_scorse[$sValue['school_code']]['w_people'] += 1;
						}
					}
            //重构数据
            if (!empty($nout_scorse)) {
                foreach ($nout_scorse as $skey => $value) {
                    //$schooldata[$value['school_code']] = $value['school_name']; 
                    if ($value['l_people'] > 0) {
                        $value['ylk_num'] = sprintf('%.2f%%', $value['yl_num'] / $value['l_people'] * 100);
                        $value['elk_num'] = sprintf('%.2f%%', $value['el_num'] / $value['l_people'] * 100);
                        $value['glk_num'] = $value['gl_num'];
                        $value['lskf'] = $value['lsk'];
                        $value['yldb_num'] = sprintf('%.2f%%', $value['nlbb_num'] / $value['l_people'] * 100);
                        $value['elcc_num'] = sprintf('%.2f%%', $value['nlcc_num'] / $value['l_people'] * 100);
                        $value['eldb_num'] = sprintf('%.2f%%', $value['nlbc_num'] / $value['l_people'] * 100);
                    } else {
                        $value['ylk_num'] = 0;
                        $value['elk_num'] = 0;
                        $value['glk_num'] = 0;
                        $value['lskf'] = 0;
                        $value['yldb_num'] = 0;
                        $value['eldb_num'] = 0;
                        $value['elcc_num'] = 0;
                    }
                    if ($value['w_people'] > 0) {
                        $value['ywk_num'] = sprintf('%.2f%%', $value['yw_num'] / $value['w_people'] * 100);
                        $value['ewk_num'] = sprintf('%.2f%%', $value['ew_num'] / $value['w_people'] * 100);
                        $value['gwk_num'] = $value['gw_num'];
                        $value['wskf'] = $value['wsk'];
                        $value['ywdb_num'] = sprintf('%.2f%%', $value['nwbb_num'] / $value['w_people'] * 100);
                        $value['ewcc_num'] = sprintf('%.2f%%', $value['nwcc_num'] / $value['w_people'] * 100);
                        $value['ewdb_num'] = sprintf('%.2f%%', $value['nwbc_num'] / $value['w_people'] * 100);
                    } else {
                        $value['ywk_num'] = 0;
                        $value['ewk_num'] = 0;
                        $value['gwk_num'] = 0;
                        $value['wskf'] = 0;
                        $value['ywdb_num'] = 0;
                        $value['ewcc_num'] = 0;
                        $value['ewdb_num'] = 0;
                    }
                    $nout_scorse[$skey] = $value;
                }
            }
            $out_scorse += $nout_scorse;
        }
        $data['exam_id'] = $exam_id;
        $data['glk_point'] = $glk_point;
        $data['gwk_point'] = $gwk_point;
        $data['school'] = $schoolArray;
        $this->title = '区外学校对比分析';
        if ($info['import'] == '导出') {
            $this->import($data, $out_scorse);
            exit;
        }
        $this->render('schoolContrast', array('scorse' => $out_scorse, 'data' => $data));
    }
    public function actionAjaxvalue() {
        $this->__common();
        //项目对应的分数线
        $data = $this->request->getParam('data');
        $zExam = new zExam();
        $scorse = $zExam->_getEduScoreArray($data['exam_id']);
        $ylk_point = $elk_point = $ywk_point = $ewk_point = $glk_point = $gwk_point = 0;
        if (isset($scorse[1])) {
            $ylk_point = $scorse[1]['score_type1'];
            $elk_point = $scorse[1]['score_type2'];
            $glk_point = $scorse[1]['score_type3'];
        }
        if (isset($scorse[2])) {
            $ywk_point = $scorse[2]['score_type1'];
            $ewk_point = $scorse[2]['score_type2'];
            $gwk_point = $scorse[2]['score_type3'];
        }
        //项目对应的学校
        $school_code = (!empty($data['schoolNameVal'])) ? "'" . implode("','", $data['schoolNameVal']) . "'" : '';
        $schooldata = array();
        $lwSubject = self::_getDBnum(); //得到分数段科目对应的栏位
        $out_scorse = $return_data = $ddata = $sdata = $gdata = array();
        //得到达C率
        $zExamRule = new ZExamRule();
        $garding_cid = $zExamRule->_getGradingCpoint();
        $garding_bid = $zExamRule->_getGradingBpoint();
        $gcdata = $gbdata = array();
        if ($garding_cid > 0) {
            //得到达标科目分数
            $gradingsql = 'SELECT * FROM "{{point_grading}}" WHERE "exam_id" = :exam_id AND "grading_id" = :g_id ';
            $gresult = Yii::app()->db->createCommand($gradingsql);
            $gresult->bindParam(':exam_id', $exam_id, PDO::PARAM_STR);
            $gresult->bindParam(':g_id', $garding_cid, PDO::PARAM_STR);
            $gradingdatac = $gresult->queryAll();
            if (!empty($gradingdatac)) {
                foreach ($gradingdatac as $gcVal) {
                    $gcdata[$gcVal['subject_id']] = $gcVal['score'];
                }
            }
        }
        //得到达B率
        if ($garding_bid > 0) {
            //得到达标科目分数
            $gradingsql = 'SELECT * FROM "{{point_grading}}" WHERE "exam_id" = :exam_id AND "grading_id" = :g_id ';
            $gresult = Yii::app()->db->createCommand($gradingsql);
            $gresult->bindParam(':exam_id', $exam_id, PDO::PARAM_STR);
            $gresult->bindParam(':g_id', $garding_bid, PDO::PARAM_STR);
            $gradingdatab = $gresult->queryAll();
            if (!empty($gradingdatab)) {
                foreach ($gradingdatab as $gbVal) {
                    $gbdata[$gbVal['subject_id']] = $gbVal['score'];
                }
            }
        }
        $zEdu = new ZEdu();
        //得到科目
        $subjectObject = $zEdu->_getSubjectObject();
        $gardingCArray = $zExamRule->_getExamGarding($exam_id, $garding_cid, $subjectObject); //得到想关类型分数C
        $gardingBArray = $zExamRule->_getExamGarding($exam_id, $garding_bid, $subjectObject); //得到想关类型分数B
        $schoolname = $yzrow = $ywrow = $ylrow = $ydbzrow = $ydbwrow = $ydblrow = $ezrow = $ewrow = $elrow = $gzrow = $gwrow = $glrow = $gfzrow = $gfwrow = $gflrow = array();
        $qWhere = '';
        //此学校所有数据(区外)
        if ($this->user_role_list != 1) {
            $zExam = new zExam();
            $qWhere = $zExam->_getSchoolInfoList($this->user_school_list);
        }
        $schoolsql = 'SELECT * FROM "{{student_out_score}}" WHERE "exam_id" = :exam_id AND "statis" = \'T\'';  //是否加用户所属学校条件
        if (!empty($school_code)) {
            $schoolsql .= 'AND "school_code" IN (' . $school_code . ') ';
        } else {
            if (!empty($qWhere)) {
                $schoolsql .= " AND ( " . $qWhere . " ) ";
            }
        }
        $schoolary = Yii::app()->db->createCommand($schoolsql);
        $schoolary->bindParam(':exam_id', $data['exam_id'], PDO::PARAM_STR);
        $schooldata = $schoolary->queryAll();
        if (!empty($schooldata)) {
            $skf = 0;
            foreach ($schooldata as $k => $value) {
                $out_scorse[$value['school_code']]['school_name'] = $value['school_name'];
                $out_scorse[$value['school_code']]['school_code'] = $value['school_code'];
                //达B的类别科目信息
                $dArray = $sArray = $pArray = array();
                if (!empty($value['disciplin_code'])) {
                    if (isset($ddata[$value['disciplin_code']])) {
                        $dArray = $ddata[$value['disciplin_code']];
                    } else {
                        $disciplinsql = 'SELECT "disciplin_id" FROM "{{disciplin}}" WHERE "disciplin_code" = :d_code ';
                        $dresult = Yii::app()->db->createCommand($disciplinsql);
                        $dresult->bindParam(':d_code', $value['disciplin_code'], PDO::PARAM_STR);
                        $dArray = $dresult->queryRow();
                        $ddata[$value['disciplin_code']] = $dArray;
                    }
                    //得到科别信息
                    if (!empty($dArray)) {
                        if (isset($sdata[$dArray['disciplin_id']])) {
                            $sArray = $sdata[$dArray['disciplin_id']];
                        } else {
                            $disciplin_subjectsql = 'SELECT "subject_id" FROM "{{disciplin_subject}}" WHERE "disciplin_id" = :d_id ';
                            $subjectids = Yii::app()->db->createCommand($disciplin_subjectsql);
                            $subjectids->bindParam(':d_id', $dArray['disciplin_id'], PDO::PARAM_STR);
                            $sArray = $subjectids->queryAll();
                            $sdata[$dArray['disciplin_id']] = $sArray;
                        }
                    }
                }
                $skf = $value['ywf'] + $value['sxf'] + $value['yyf'];
                //得到文理科人数
                if (!isset($out_scorse[$value['school_code']]['l_people'])) {
                    $out_scorse[$value['school_code']]['l_people'] = 0;
                }
                if (!isset($out_scorse[$value['school_code']]['w_people'])) {
                    $out_scorse[$value['school_code']]['w_people'] = 0;
                }
                //得到分数线人数
                if ($value['disciplin_type'] == 1) {
                    if (!isset($out_scorse[$value['school_code']]['yl_num'])) {
                        $out_scorse[$value['school_code']]['yl_num'] = 0;  //一本人数
                    }
                    if (!isset($out_scorse[$value['school_code']]['el_num'])) {
                        $out_scorse[$value['school_code']]['el_num'] = 0; //二本人数
                    }
                    if (!isset($out_scorse[$value['school_code']]['ybbl_num'])) {
                        $out_scorse[$value['school_code']]['ybbl_num'] = 0; //2b
                    }
                    if (!isset($out_scorse[$value['school_code']]['ebcl_num'])) {
                        $out_scorse[$value['school_code']]['ebcl_num'] = 0; //达到bc
                    }
                    if (!isset($out_scorse[$value['school_code']]['eccl_num'])) {
                        $out_scorse[$value['school_code']]['eccl_num'] = 0; //达到2c
                    }
                    if (!isset($out_scorse[$value['school_code']]['gl_num'])) {
                        $out_scorse[$value['school_code']]['gl_num'] = 0; //高分段人数
                    }
                    if (!isset($out_scorse[$value['school_code']]['lsk'])) {
                        $out_scorse[$value['school_code']]['lsk'] = 0;
                    }
                    $lndb = 0;
                    //理科分数线人数
                    if ($skf >= $ylk_point) {
                        $out_scorse[$value['school_code']]['yl_num'] += 1;
                        if (!empty($sArray)) {
                            foreach ($sArray as $sVal) {
                                $pkey = isset($lwSubject[$sVal['subject_id']]) ? $lwSubject[$sVal['subject_id']] : ''; //科目栏位
                                $pcpoint = isset($gcdata[$sVal['subject_id']]) ? $gcdata[$sVal['subject_id']] : 0;  //C分数线
                                $pbpoint = isset($gbdata[$sVal['subject_id']]) ? $gbdata[$sVal['subject_id']] : 0;  //B分数线
                                //得到达2b的人数
                                $nPoint = isset($value[$pkey]) ? $value[$pkey] : 0; //科目分数
                                if ($nPoint >= $pbpoint) {
                                    $lndb += 2;  //达到b
                                }
                            }
                            if ($lndb >= 4) {
                                $out_scorse[$value['school_code']]['ybbl_num'] += 1;  //理科达到2b人数
                            }
                        }
                    }
                    $lndb = 0;
                    if ($skf >= $elk_point) {
                        $out_scorse[$value['school_code']]['el_num'] += 1;
                        if (!empty($sArray)) {
                            foreach ($sArray as $sVal) {
                                $pkey = isset($lwSubject[$sVal['subject_id']]) ? $lwSubject[$sVal['subject_id']] : ''; //科目栏位
                                $pcpoint = isset($gcdata[$sVal['subject_id']]) ? $gcdata[$sVal['subject_id']] : 0;  //C分数线
                                $pbpoint = isset($gbdata[$sVal['subject_id']]) ? $gbdata[$sVal['subject_id']] : 0;  //B分数线
                                //得到达bc的人数
                                $nPoint = isset($value[$pkey]) ? $value[$pkey] : 0; //科目分数
                                if ($nPoint >= $pbpoint) {
                                    $lndb += 3;  //达到b
                                } elseif ($nPoint >= $pcpoint) {
                                    $lndb += 2;  //达到c
                                }
                            }
                            if ($lndb >= 5) {
                                $out_scorse[$value['school_code']]['ebcl_num'] += 1;  //理科达到bc人数
                                $out_scorse[$value['school_code']]['eccl_num'] += 1; // 理科达到2c人数
                            }elseif($lndb>=4){
                                $out_scorse[$value['school_code']]['eccl_num'] += 1; //理科达到2c人数
                            }
                        }
                    }
                    //理科高分段
                    if ($skf >= $glk_point) {
                        $out_scorse[$value['school_code']]['gl_num'] += 1;
                    }
                    //理科最高分
                    if ($skf > $out_scorse[$value['school_code']]['lsk']) {
                        $out_scorse[$value['school_code']]['lsk'] = $skf;
                    }
                    $out_scorse[$value['school_code']]['l_people'] += 1;
                } elseif ($value['disciplin_type'] == 2) {
                    if (!isset($nout_scorse[$sValue['school_code']]['yw_num'])) {
                        $nout_scorse[$sValue['school_code']]['yw_num'] = 0;  //一本人数
                    }
                    if (!isset($nout_scorse[$sValue['school_code']]['ew_num'])) {
                        $nout_scorse[$sValue['school_code']]['ew_num'] = 0; //二本人数
                    }
                    if (!isset($nout_scorse[$sValue['school_code']]['nwbb_num'])) {
                        $nout_scorse[$sValue['school_code']]['nwbb_num'] = 0; //达B
                    }
                    if (!isset($nout_scorse[$sValue['school_code']]['nwbc_num'])) {
                        $nout_scorse[$sValue['school_code']]['nwbc_num'] = 0; //达bc
                    }
                    if (!isset($nout_scorse[$sValue['school_code']]['nwcc_num'])) {
                        $nout_scorse[$sValue['school_code']]['nwcc_num'] = 0; //达cc
                    }
                    if (!isset($nout_scorse[$sValue['school_code']]['gw_num'])) {
                        $nout_scorse[$sValue['school_code']]['gw_num'] = 0; //高分段
                    }
                    if (!isset($nout_scorse[$sValue['school_code']]['wsk'])) {
                        $nout_scorse[$sValue['school_code']]['wsk'] = 0;
                    }
                    $lndb = 0;
                    //理科分数线人数
                    if ($skf >= $ywk_point) {
                        $nout_scorse[$sValue['school_code']]['yw_num'] += 1;
                        if (!empty($sArray)) {
                            foreach ($sArray as $sVal) {
                                $pkey = isset($lwSubject[$sVal['subject_id']]) ? $lwSubject[$sVal['subject_id']] : ''; //科目栏位
                                $pcpoint = isset($gcdata[$sVal['subject_id']]) ? $gcdata[$sVal['subject_id']] : 0;  //C分数线
                                $pbpoint = isset($gbdata[$sVal['subject_id']]) ? $gbdata[$sVal['subject_id']] : 0;  //B分数线
                                //得到达2b的人数
                                $nPoint = isset($sValue[$pkey]) ? $sValue[$pkey] : 0; //科目分数
                                if ($nPoint >= $pbpoint) {
                                    $lndb += 2;  //达到b
                                }
                            }
                            if ($lndb >= 4) {
                                $nout_scorse[$sValue['school_code']]['nwbb_num'] += 1;  //理科达到2b人数
                            }
                        }
                    }
                    $lndb = 0;
                    if ($skf >= $ewk_point) {
                        $nout_scorse[$sValue['school_code']]['ew_num'] += 1;
                        if (!empty($sArray)) {
                            foreach ($sArray as $sVal) {
                                $pkey = isset($lwSubject[$sVal['subject_id']]) ? $lwSubject[$sVal['subject_id']] : ''; //科目栏位
                                $pcpoint = isset($gcdata[$sVal['subject_id']]) ? $gcdata[$sVal['subject_id']] : 0;  //C分数线
                                $pbpoint = isset($gbdata[$sVal['subject_id']]) ? $gbdata[$sVal['subject_id']] : 0;  //B分数线
                                //得到达bc的人数
                                $nPoint = isset($sValue[$pkey]) ? $sValue[$pkey] : 0; //科目分数
                                if ($nPoint >= $pbpoint) {
                                    $lndb += 3;  //达到b
                                } elseif ($nPoint >= $pcpoint) {
                                    $lndb += 2;  //达到c
                                }
                            }
                            if ($lndb >= 5) {
                                $nout_scorse[$sValue['school_code']]['nwbc_num'] += 1;  //理科达到bc人数
                                $nout_scorse[$sValue['school_code']]['nwcc_num'] += 1; // 理科达到2c人数
                            }elseif($lndb>=4){
                                $nout_scorse[$sValue['school_code']]['nwcc_num'] += 1; //理科达到2c人数
                            }
                        }
                    }
                    //文科高分段人数
                    if ($skf >= $gwk_point) {
                        $nout_scorse[$sValue['school_code']]['gw_num'] += 1;
                    }
                    //文科最高分
                    if ($skf > $nout_scorse[$sValue['school_code']]['wsk']) {
                        $nout_scorse[$sValue['school_code']]['wsk'] = $skf;
                    }
                    $nout_scorse[$sValue['school_code']]['w_people'] += 1;
                }
            }
            if(!empty($out_scorse)){
                foreach($out_scorse as $key => $oVal){
                    $schoolname[] = $oVal['school_name'];
                    $yl_bl = $ywdb_bl = $el_bl = $gl_bl = $gl_f = 0;
                    if($oVal['l_people']>0){
                        $yl_bl = abs(sprintf('%.2f', $oVal['yl_num'] / $oVal['l_people'] * 100));
                        $ywdb_bl = abs(sprintf('%.2f', $oVal['ybbl_num'] / $oVal['l_people'] * 100));
                        $el_bl = sprintf('%.2f', $oVal['el_num'] / $oVal['l_people'] * 100);
                        $gl_bl = sprintf('%.2f', $oVal['gl_num'] / $oVal['l_people'] * 100);
                        $gl_f = $oVal['lsk'];
                    }
                    $ylrow[] = $yl_bl;
                    $ydblrow[] = $ywdb_bl;
                    $elrow[] = $el_bl;
                    $gflrow[] = $gl_f; 
                    $glrow[] = $gl_bl;
                    $yw_bl = $yldb_bl = $ew_bl = $gw_bl = $gw_f = 0;
                    if($oVal['w_people']>0){
                        $yw_bl = abs(sprintf('%.2f', $oVal['yw_num'] / $oVal['w_people'] * 100));
                        $yldb_bl = abs(sprintf('%.2f', $oVal['nwbb_num'] / $oVal['w_people'] * 100));
                        $ew_bl = abs(sprintf('%.2f', $oVal['ew_num'] /$oVal['w_people'] * 100));
                        $gw_bl = sprintf('%.2f', $oVal['gw_num'] / $oVal['w_people'] * 100);
                        $gw_f = $oVal['gw_num'];
                    } 
                    $ywrow[] = $yw_bl;
                    $yzrow[] = $yl_bl + $yw_bl;
                    $ydbwrow[] = $yldb_bl;
                    $ydbzrow[] = $ywdb_bl + $yldb_bl;
                    $ewrow[] = $ew_bl;
                    $ezrow[] = $el_bl + $ew_bl;
                    $gfwrow[] = $gw_f;
                    $gfzrow[] = $gl_f+$gw_f;
                    $gwrow[] = $gw_bl;
                    $gzrow[] = $gl_bl + $gw_bl;  
				}
			}
		}
		if ($data['statisticsType_navVal']==1 && $data['statisticsType_navSunVal']==0){
			$date['yzrow'] = $yzrow;
			$date['ywrow'] = $ywrow;
			$date['ylrow'] = $ylrow;
		}
		if ($data['statisticsType_navVal']==1 && $data['statisticsType_navSunVal']==1){
			$date['yzrow'] = $ydbzrow;
			$date['ywrow'] = $ydbwrow;
			$date['ylrow'] = $ydblrow;
		}
		if ($data['statisticsType_navVal']==2 && $data['statisticsType_navSunVal']==0){
			$date['yzrow'] = $ezrow;
			$date['ywrow'] = $ewrow;
			$date['ylrow'] = $elrow;
		}
		if ($data['statisticsType_navVal']==3){
			$date['yzrow'] = $gzrow;
			$date['ywrow'] = $gwrow;
			$date['ylrow'] = $glrow;
		}
		if ($data['statisticsType_navVal']==4){
			$date['yzrow'] = $gfzrow;
			$date['ywrow'] = $gfwrow;
			$date['ylrow'] = $gflrow;
		}
		$date['schoolname'] = $schoolname;
		echo json_encode($date);
	}
        
    /**
     * 导出
     * 
     * @version 1.0
     */
    public function import($data, $out_scorse) {
        spl_autoload_unregister(array('YiiBase', 'autoload'));
        include_once(dirname(dirname(dirname(dirname(__FILE__)))) . '/extensions/PHPExcel.php');
        include_once(dirname(dirname(dirname(dirname(__FILE__)))) . '/extensions/PHPExcel/IOFactory.php');
        $objPHPExcel = new PHPExcel();
        $objPHPExcel->setActiveSheetIndex(0)
                ->setCellValue('A1', '学校')
                ->setCellValue('B1', '本一率')
                ->setCellValue('F1', '本二率')
                ->setCellValue('L1', '高分段（人数）')
                ->setCellValue('N1', '最高分');
        $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(15);
        $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(25);
        $objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(25);
        $objPHPExcel->getActiveSheet()->getColumnDimension('L')->setWidth(25);
        $objPHPExcel->getActiveSheet()->getColumnDimension('N')->setWidth(25);
        $objPHPExcel->setActiveSheetIndex(0)->mergeCells('A1:A2:A3');
        $objPHPExcel->setActiveSheetIndex(0)->mergeCells('B1:C1:D1:E1');
        $objPHPExcel->setActiveSheetIndex(0)->mergeCells('F1:G1:H1:I1:J1:K1');
        $objPHPExcel->setActiveSheetIndex(0)->mergeCells('L1:M1');
        $objPHPExcel->setActiveSheetIndex(0)->mergeCells('N1:O1');
        $objPHPExcel->setActiveSheetIndex(0)
                ->setCellValue('B2', '文科')
                ->setCellValue('D2', '理科')
                ->setCellValue('F2', '文科')
                ->setCellValue('I2', '理科')
                ->setCellValue('L2', "文科(" . $data['glk_point'] . ")")
                ->setCellValue('M2', "理科(" . $data['gwk_point'] . ")")
                ->setCellValue('N2', '文科')
                ->setCellValue('O2', '理科');
        $objPHPExcel->setActiveSheetIndex(0)->mergeCells('B2:C2');
        $objPHPExcel->setActiveSheetIndex(0)->mergeCells('D2:E2');
        $objPHPExcel->setActiveSheetIndex(0)->mergeCells('F2:G2:H2');
        $objPHPExcel->setActiveSheetIndex(0)->mergeCells('I2:J2:K2');
        $objPHPExcel->setActiveSheetIndex(0)->mergeCells('L2:L3');
        $objPHPExcel->setActiveSheetIndex(0)->mergeCells('M2:M3');
        $objPHPExcel->setActiveSheetIndex(0)->mergeCells('N2:N3');
        $objPHPExcel->setActiveSheetIndex(0)->mergeCells('O2:O3');
        $objPHPExcel->setActiveSheetIndex(0)
                ->setCellValue('B3', '总分上线')
                ->setCellValue('C3', '总分+2B')
                ->setCellValue('D3', '总分上线')
                ->setCellValue('E3', '总分+2B')
                ->setCellValue('F3', '总分上线')
                ->setCellValue('G3', '总分+BC')
                ->setCellValue('H3', '总分+CC')
                ->setCellValue('I3', '总分上线')
                ->setCellValue('J3', '总分+BC')
                ->setCellValue('K3', '总分+CC');

        $i = 4;
        foreach ($out_scorse as $v) {
            $objPHPExcel->setActiveSheetIndex(0)
                    ->setCellValue('A' . $i, $v['school_name'])
                    ->setCellValue('B' . $i, $v['ywk_num'])
                    ->setCellValue('C' . $i, $v['ywdb_num'])
                    ->setCellValue('D' . $i, $v['ylk_num'])
                    ->setCellValue('E' . $i, $v['yldb_num'])
                    ->setCellValue('F' . $i, $v['ewk_num'])
                    ->setCellValue('G' . $i, $v['ewdb_num'])
                    ->setCellValue('H' . $i, $v['ewcc_num'])
                    ->setCellValue('I' . $i, $v['elk_num'])
                    ->setCellValue('J' . $i, $v['eldb_num'])
                    ->setCellValue('K' . $i, $v['elcc_num'])
                    ->setCellValue('L' . $i, $v['gwk_num'])
                    ->setCellValue('M' . $i, $v['glk_num'])
                    ->setCellValue('N' . $i, $v['wskf'])
                    ->setCellValue('O' . $i, $v['lskf']);
            $i++;
        }
        $objPHPExcel->setActiveSheetIndex(0);
        $file_nams = "区外学校对比分析报表";
        $file_nams .= ".xls";
        if (preg_match("/MSIE/", $_SERVER["HTTP_USER_AGENT"])) {
            $file_nams = urlencode($file_nams);
            $file_nams = str_replace("+", "%20", $file_nams); // 替换空格
        }
        ob_end_clean();
		header("Content-Type: application/vnd.ms-excel;charset=utf-8");
        header("Content-Disposition: attachment; filename=" . $file_nams);
        header('Cache-Control:must-revalidate,post-check=0,pre-check=0');
        header('Expires:0');
        header('Pragma:public');
        $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
        $objWriter->save('php://output');
        Yii::app()->end();
        spl_autoload_register(array('YiiBase', 'autoload'));
        exit();
    }

    /**
     * 得到2B率
     * 
     * @version 1.0
     * @date 2014-02-16
     */
    protected function _getDBnum() {
        //解决分数问题对应的科目id（前提科目名称必须对应）
        $pointObject = array(
            '物理' => 'wlf',
            '化学' => 'hxf',
            '生物' => 'swf',
            '历史' => 'lsf',
            '政治' => 'zzf',
            '地理' => 'dlf'
        );
        $subjectObject = array();

        $sql = 'SELECT "subject_id","subject_name" FROM "{{subject}}" WHERE "is_del" = 0';
        $result = Yii::app()->db->createcommand($sql);
        $data = $result->queryAll();
        if (!empty($data)) {
            foreach ($data as $value) {
                $key = isset($pointObject[$value['subject_name']]) ? $pointObject[$value['subject_name']] : '';
                if (!empty($key)) {
                    $subjectObject[$value['subject_id']] = $key;
                }
            }
        }
        return $subjectObject;
    }
        
    /**
     * 得到达标科目分数
     * 
     * @version 1.0
     * @date 2014-02-16
     */
    protected function _getDbPoint($exam_id){
        

        
        
        $gdata = array();
        
        if ($exam_id > 0) {
            $gradingsql = 'SELECT * FROM "{{point_grading}}" WHERE "exam_id" = :exam_id AND "grading_id" IN(4,5) ';
            $gresult = Yii::app()->db->createCommand($gradingsql);
            $gresult->bindParam(':exam_id', $exam_id, PDO::PARAM_STR);
            $gradingdata = $gresult->queryAll();
                    
            if (!empty($gradingdata)) {
                foreach ($gradingdata as $gVal) {
                    $gdata[$gVal['subject_id']][$gVal['grading_id']] = $gVal['score'];
                    
                    
                }
                
            }
                    }
                    
                    
                    
                    
                    
                    
        
                
        return $gdata;
        
    }
    
}